// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// q [author] rhyme_lph
// f [email]  rhymelph@gmail.com
// L [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/entities/plans_item_entity.dart';
import 'package:finance_app/src/entities/plans_top_content_entity.dart';
import 'package:finance_app/src/provider/setting/subscription_provider.dart';
import 'package:finance_app/src/router_gen/router_gen_providers.dart';
import 'package:finance_app/src/utils/date_time_utils.dart';
import 'package:finance_app/src/widgets/bottom_sheet/transactions_got_it_tip_bottom_sheet.dart';

class SubPlansProvider extends BaseProvider {
  List<PlansTopContentEntity> topContents = [];
  List<PlansItemEntity> monthlyList = [];
  List<PlansItemEntity> annuallyList = [];
  List<String> tabs = [
    S.current.monthly,
    S.current.annually,
  ];

  @override
  Future get dataFuture => null;

  void onChangeStandard() {}

  void onUpgrade([PlansItemEntity item]) async {
    DateTime from = DateTime.now();
    DateTime until =
        from.add(Duration(days: item.type == 'monthly' ? 30 : 360));
    bool sameYear = from.year == until.year;

    String billingPeriod =
        '${DateTimeUtils.formatDateTime(from, sameYear ? 'd MMM' : 'd MMM yyyy')} - ${DateTimeUtils.formatDateTime(until, 'd MMM yyyy')}';

    final result =
        await Routes.navigateTo(RouterGenProviders.subPaymentPage, params: {
      'plan': item,
      'billingPeriod': billingPeriod,
    });
    if (result == true) {
      if (result == true) {
        getParentProvider<SubscriptionProvider>().onTry();
      }
    }
  }

  void onShowTransactionTip() {
    obtainContext?.call((context) {
      showTransactionsGotItTipBottomSheet(context);
    });
  }
}
